package cn.net.zidian.mvvm.vm;

import com.blankj.utilcode.util.ToastUtils;

import java.util.List;

import cn.net.zidian.api.ApiRepository;
import cn.net.zidian.bean.AstroBean;
import cn.net.zidian.bean.ResultBean;
import cn.net.zidian.bean.TodayBean;
import cn.net.zidian.event.SingleLiveEvent;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.observers.DisposableObserver;

public class TodayVM extends BaseViewModel {

    public SingleLiveEvent<List<TodayBean>> eventList = new SingleLiveEvent<>();

    public void getList() {
        ApiRepository.getTodayHistory()
                .safeSubscribe(new DisposableObserver<ResultBean<List<TodayBean>>>() {
                    @Override
                    public void onNext(@NonNull ResultBean<List<TodayBean>> result) {
                        if (result.getStatus() == 0) {
                            eventList.setValue(result.getResult());
                        } else {
                            ToastUtils.showShort(result.getMsg());
                        }
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        ToastUtils.showShort("网络请求失败");
                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }
}
